<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const numOfPairs = (nums, target) => {
      let res = 0;
      const len = nums.length;
      for (let i = 0; i < len; i++) {
        // 若开头就对不上，直接进行下一个的判断
        if (target.indexOf(nums[i]) !== 0) continue;
        for (let j = 0; j < len; j++) {
          // 排除i===j的情况
          if (i === j) continue;
          if (nums[i] + nums[j] === target) res++;
        }
      }
      return res;
    };
    console.log(numOfPairs(["777", "7", "77", "77"], "7777"));
  </script>
</body>

</html>